home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / mee / vbdao / visdata / dynaset.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  29.2 KB  |  974 lines

  1. VERSION 2.00
  2. Begin Form fDynaset 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3750
  5.    ClientLeft      =   1410
  6.    ClientTop       =   2415
  7.    ClientWidth     =   5655
  8.    Height          =   4155
  9.    Icon            =   0
  10.    Left            =   1350
  11.    LinkTopic       =   "Form1"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3733.906
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   5675.316
  16.    Tag             =   "Dynaset"
  17.    Top             =   2070
  18.    Width           =   5775
  19.    Begin PictureBox FieldHeader 
  20.       BackColor       =   &H00C0C0C0&
  21.       BorderStyle     =   0  'None
  22.       Height          =   240
  23.       Left            =   0
  24.       ScaleHeight     =   240
  25.       ScaleMode       =   0  'User
  26.       ScaleWidth      =   5028
  27.       TabIndex        =   16
  28.       Top             =   480
  29.       Width           =   5025
  30.       Begin Label FieldValueLabel 
  31.          BackColor       =   &H00C0C0C0&
  32.          Caption         =   " Value  (F4=Zoom) "
  33.          Height          =   255
  34.          Left            =   1680
  35.          TabIndex        =   18
  36.          Top             =   0
  37.          Width           =   3165
  38.       End
  39.       Begin Label FieldHdrLabel 
  40.          BackColor       =   &H00C0C0C0&
  41.          Caption         =   "Field Name:"
  42.          Height          =   252
  43.          Left            =   120
  44.          TabIndex        =   17
  45.          Top             =   0
  46.          Width           =   1212
  47.       End
  48.    End
  49.    Begin PictureBox ViewButtons 
  50.       Align           =   1  'Align Top
  51.       BackColor       =   &H00C0C0C0&
  52.       BorderStyle     =   0  'None
  53.       Height          =   495
  54.       Left            =   0
  55.       ScaleHeight     =   495
  56.       ScaleMode       =   0  'User
  57.       ScaleWidth      =   5658.375
  58.       TabIndex        =   0
  59.       Top             =   0
  60.       Width           =   5655
  61.       Begin CommandButton SortButton 
  62.          Caption         =   "&Sort"
  63.          Height          =   330
  64.          Left            =   3128
  65.          TabIndex        =   24
  66.          Top             =   0
  67.          Width           =   650
  68.       End
  69.       Begin CommandButton FilterButton 
  70.          Caption         =   "F&ilter"
  71.          Height          =   330
  72.          Left            =   2520
  73.          TabIndex        =   23
  74.          Top             =   0
  75.          Width           =   650
  76.       End
  77.       Begin CommandButton CloseButton 
  78.          Cancel          =   -1  'True
  79.          Caption         =   "&Close"
  80.          Height          =   330
  81.          Left            =   4367
  82.          TabIndex        =   9
  83.          TabStop         =   0   'False
  84.          Top             =   0
  85.          Width           =   650
  86.       End
  87.       Begin CommandButton PropButton 
  88.          Caption         =   "&Prop"
  89.          Height          =   330
  90.          Left            =   3738
  91.          TabIndex        =   5
  92.          Top             =   0
  93.          Width           =   650
  94.       End
  95.       Begin CommandButton DelButton 
  96.          Caption         =   "&Del"
  97.          Height          =   330
  98.          Left            =   1260
  99.          TabIndex        =   4
  100.          Top             =   0
  101.          Width           =   650
  102.       End
  103.       Begin CommandButton EditButton 
  104.          Caption         =   "&Edit"
  105.          Height          =   330
  106.          Left            =   630
  107.          TabIndex        =   3
  108.          Top             =   0
  109.          Width           =   650
  110.       End
  111.       Begin CommandButton AddButton 
  112.          Caption         =   "&Add"
  113.          Height          =   330
  114.          Left            =   0
  115.          TabIndex        =   2
  116.          Top             =   0
  117.          Width           =   650
  118.       End
  119.       Begin CommandButton FindButton 
  120.          Caption         =   "&Find"
  121.          Height          =   330
  122.          Left            =   1890
  123.          TabIndex        =   1
  124.          Top             =   0
  125.          Width           =   650
  126.       End
  127.    End
  128.    Begin PictureBox ChangeButtons 
  129.       BackColor       =   &H00C0C0C0&
  130.       BorderStyle     =   0  'None
  131.       Height          =   480
  132.       Left            =   0
  133.       ScaleHeight     =   480
  134.       ScaleMode       =   0  'User
  135.       ScaleWidth      =   5028
  136.       TabIndex        =   6
  137.       Top             =   0
  138.       Visible         =   0   'False
  139.       Width           =   5028
  140.       Begin CommandButton UpdateButton 
  141.          Caption         =   "&Update"
  142.          Height          =   372
  143.          Left            =   960
  144.          TabIndex        =   8
  145.          Top             =   48
  146.          Width           =   1212
  147.       End
  148.       Begin CommandButton CancelButton 
  149.          Caption         =   "&Cancel"
  150.          Height          =   372
  151.          Left            =   2640
  152.          TabIndex        =   7
  153.          Top             =   48
  154.          Width           =   1212
  155.       End
  156.    End
  157.    Begin PictureBox StatBox 
  158.       Align           =   2  'Align Bottom
  159.       BackColor       =   &H00C0C0C0&
  160.       BorderStyle     =   0  'None
  161.       Height          =   281
  162.       Left            =   0
  163.       ScaleHeight     =   298.153
  164.       ScaleMode       =   0  'User
  165.       ScaleWidth      =   5665.188
  166.       TabIndex        =   14
  167.       Top             =   3465
  168.       Width           =   5655
  169.       Begin CommandButton NextButton 
  170.          Caption         =   ">"
  171.          Height          =   287
  172.          Left            =   4200
  173.          TabIndex        =   22
  174.          Top             =   0
  175.          Width           =   375
  176.       End
  177.       Begin CommandButton LastButton 
  178.          Caption         =   ">|"
  179.          Height          =   287
  180.          Left            =   4575
  181.          TabIndex        =   21
  182.          Top             =   0
  183.          Width           =   375
  184.       End
  185.       Begin CommandButton FirstButton 
  186.          Caption         =   "|<"
  187.          Height          =   287
  188.          Left            =   0
  189.          TabIndex        =   20
  190.          Top             =   0
  191.          Width           =   375
  192.       End
  193.       Begin CommandButton PrevButton 
  194.          Caption         =   "<"
  195.          Height          =   287
  196.          Left            =   375
  197.          TabIndex        =   19
  198.          Top             =   0
  199.          Width           =   375
  200.       End
  201.       Begin Label cStatusBar 
  202.          BackColor       =   &H00FFFFFF&
  203.          BorderStyle     =   1  'Fixed Single
  204.          Height          =   287
  205.          Left            =   749
  206.          TabIndex        =   15
  207.          Top             =   5
  208.          Width           =   3360
  209.       End
  210.    End
  211.    Begin VScrollBar cScrollBar 
  212.       Height          =   2616
  213.       LargeChange     =   3000
  214.       Left            =   5040
  215.       SmallChange     =   300
  216.       TabIndex        =   13
  217.       Top             =   720
  218.       Visible         =   0   'False
  219.       Width           =   252
  220.    End
  221.    Begin PictureBox cFields 
  222.       BackColor       =   &H00C0C0C0&
  223.       BorderStyle     =   0  'None
  224.       Height          =   375
  225.       Left            =   120
  226.       ScaleHeight     =   372
  227.       ScaleMode       =   0  'User
  228.       ScaleWidth      =   4812
  229.       TabIndex        =   10
  230.       Top             =   720
  231.       Width           =   4815
  232.       Begin TextBox cFieldData 
  233.          BackColor       =   &H00FFFFFF&
  234.          DataSource      =   "Data1"
  235.          ForeColor       =   &H00000000&
  236.          Height          =   288
  237.          Index           =   0
  238.          Left            =   1560
  239.          TabIndex        =   11
  240.          Top             =   0
  241.          Visible         =   0   'False
  242.          Width           =   3252
  243.       End
  244.       Begin Label cFieldName 
  245.          BackColor       =   &H00C0C0C0&
  246.          ForeColor       =   &H00000000&
  247.          Height          =   252
  248.          Index           =   0
  249.          Left            =   0
  250.          TabIndex        =   12
  251.          Top             =   60
  252.          Visible         =   0   'False
  253.          Width           =   1572
  254.       End
  255.    End
  256. Option Explicit
  257. 'form variables
  258. Dim FDS As Dynaset            'current form's dynaset
  259. Dim FTblName As String        'form dynaset table name
  260. Dim FBM As String             'form bookmark
  261. Dim FNotFound As Integer      'used by find function
  262. Dim FAtTop As Integer         'top flag
  263. Dim FEditFlag As Integer      'edit mode
  264. Dim FAddNewFlag As Integer    'add mode
  265. Dim FFldDataChanged As Integer
  266. Dim FFindForm As New fFind    'find form instance
  267. Dim FCurrRec As Integer       'record counter
  268. Dim FNumbRows As Long         'total rows in dynaset
  269. Dim FDynaString As String     'dynaset open string
  270. Sub AddButton_Click ()
  271.   On Error GoTo AddErr
  272.   'set the mode
  273.   FDS.AddNew
  274.   cStatusBar = "Add record"
  275.   FAddNewFlag = True
  276.   If FDS.RecordCount > 0 Then
  277.     FBM = FDS.Bookmark
  278.   Else
  279.     FBM = NULL_STR
  280.   End If
  281.   ChangeButtons.Visible = True
  282.   ViewButtons.Visible = False
  283.   NextButton.Enabled = False
  284.   FirstButton.Enabled = False
  285.   LastButton.Enabled = False
  286.   PrevButton.Enabled = False
  287.   ClearDataFields
  288.   cFieldData(0).SetFocus
  289.   GoTo AddEnd
  290. AddErr:
  291.   ShowError
  292.   Resume AddEnd
  293. AddEnd:
  294. End Sub
  295. Sub CancelButton_Click ()
  296.    On Error Resume Next
  297.    ChangeButtons.Visible = False
  298.    ViewButtons.Visible = True
  299.    NextButton.Enabled = True
  300.    FirstButton.Enabled = True
  301.    LastButton.Enabled = True
  302.    PrevButton.Enabled = True
  303.    FEditFlag = False
  304.    FAddNewFlag = False
  305.    If Len(FBM) > 0 Then FDS.Bookmark = FBM
  306.    DisplayCurrentRecord
  307. End Sub
  308. Sub cFieldData_Change (Index As Integer)
  309.   'just set the flag if data is changed
  310.   'it gets reset to false when a new record is displayed
  311.   FFldDataChanged = True
  312. End Sub
  313. Sub cFieldData_KeyDown (Index As Integer, KeyCode As Integer, Shift As Integer)
  314.   If KeyCode = &H73 Then   'F4
  315.     cFieldName_DblClick Index
  316.   ElseIf KeyCode = 34 And cScrollBar.Visible = True Then
  317.     'pagedown with > 10 fields
  318.     cScrollBar = cScrollBar - 3000
  319.   ElseIf KeyCode = 33 And cScrollBar.Visible = True Then
  320.     'pageup with > 10 fields
  321.     cScrollBar = cScrollBar + 3000
  322.   End If
  323. End Sub
  324. Sub cFieldData_KeyPress (Index As Integer, KeyAscii As Integer)
  325.   'only allow return when in edit of add mode
  326.   If FEditFlag = True Or FAddNewFlag = True Then
  327.     If KeyAscii = 13 Then
  328.       KeyAscii = 0
  329.       SendKeys "{Tab}"
  330.     End If
  331.   'throw away the keystrokes if not in add or edit mode
  332.   ElseIf FEditFlag = False And FAddNewFlag = False Then
  333.     KeyAscii = 0
  334.   End If
  335. End Sub
  336. Sub cFieldData_LostFocus (Index As Integer)
  337.   On Error GoTo FldDataErr
  338.   If FFldDataChanged = True Then
  339.     'store the data in the field
  340.     FDS(Index) = cFieldData(Index)
  341.   End If
  342.   GoTo FldDataEnd
  343. FldDataErr:
  344.   ShowError
  345.   Resume FldDataEnd
  346. FldDataEnd:
  347.   'reset for valid or error condition
  348.   FFldDataChanged = False
  349. End Sub
  350. Sub cFieldName_DblClick (Index As Integer)
  351.   On Error GoTo ZoomErr
  352.   If FDS(Index).Type = FT_STRING Or FDS(Index).Type = FT_MEMO Then
  353.      If FDS(Index).FieldSize() < GETCHUNK_CUTOFF Then
  354.        gstZoomData = cFieldData(Index)
  355.      Else
  356.        'add the rest of the field data with getchunk
  357.        MsgBar "Getting Memo Field Data", True
  358.        SetHourglass Me
  359.        gstZoomData = cFieldData(Index) + StripNonAscii(FDS(Index).GetChunk(GETCHUNK_CUTOFF, MAX_MEMO_SIZE))
  360.        ResetMouse Me
  361.        MsgBar NULL_STR, False
  362.      End If
  363.      fZoom.Caption = Mid(cFieldName(Index), 1, Len(cFieldName(Index)) - 1)
  364.      fZoom.Top = Top + 1200
  365.      fZoom.Left = Left + 250
  366.      If FAddNewFlag Or FEditFlag Then
  367.        fZoom.SaveButton.Visible = True
  368.        fZoom.CloseButton.Visible = True
  369.      Else
  370.        fZoom.CloseZoomButton.Visible = True
  371.      End If
  372.      If FDS(Index).Type <> FT_MEMO Then
  373.        fZoom.cData = gstZoomData
  374.        fZoom.Height = 1125
  375.      Else
  376.        fZoom.cMemo = gstZoomData
  377.        fZoom.cMemo.Visible = True
  378.        fZoom.cData.Visible = False
  379.        fZoom.Height = 2205
  380.      End If
  381.      fZoom.Show MODAL
  382.      If (FAddNewFlag Or FEditFlag) And gstZoomData <> "__CANCELLED__" Then
  383.        If FDS(Index).Type = FT_STRING And Len(gstZoomData) > FDS(Index).Size Then
  384.          Beep
  385.          MsgBox "Field Length Exceeded, Data Truncated!", 48
  386.          cFieldData(Index) = Mid(gstZoomData, 1, FDS(Index).Size)
  387.        Else
  388.          cFieldData(Index) = gstZoomData
  389.        End If
  390.        FDS(Index) = cFieldData(Index)
  391.        FFldDataChanged = False
  392.      End If
  393.   End If
  394.   GoTo ZoomEnd
  395. ZoomErr:
  396.   ShowError
  397.   Resume ZoomEnd
  398. ZoomEnd:
  399. End Sub
  400. Sub ClearDataFields ()
  401.   Dim i As Integer
  402.   'clear out the fields on the main form
  403.   For i = 0 To FDS.Fields.Count - 1
  404.     cFieldData(i) = NULL_STR
  405.   Next
  406. End Sub
  407. Sub CloseButton_Click ()
  408.   Unload Me
  409. End Sub
  410. Sub cScrollBar_Change ()
  411.   Dim t As Integer
  412.   t = cScrollBar
  413.   If (t - 720) Mod 300 = 0 Then
  414.     cFields.Top = t
  415.   Else
  416.     cFields.Top = ((t - 720) \ 300) * 300 + 720
  417.   End If
  418. End Sub
  419. Sub DelButton_Click ()
  420.   On Error GoTo DelRecErr
  421.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  422.     FDS.Delete
  423.     If gfTransPending Then gfDBChanged = True
  424.     If FDS.EOF = False Then
  425.       FDS.MoveNext
  426.     End If
  427.     FNumbRows = FNumbRows - 1
  428.     DisplayCurrentRecord
  429.   End If
  430.   GoTo DelRecEnd
  431. DelRecErr:
  432.   ShowError
  433.   Resume DelRecEnd
  434. DelRecEnd:
  435. End Sub
  436. Sub DisplayCurrentRecord ()
  437.    Dim i As Integer
  438.    Dim cst As String    'current status bar
  439.    On Error GoTo DCRErr
  440.    SetHourglass Me
  441.    cst = "Record "
  442.    'check BOF/EOF flag so we know if we
  443.    'are sitting on a valid record
  444.    If FAddNewFlag = True Then
  445.      cst = cst + CStr(FCurrRec) & " of " & CStr(FNumbRows)
  446.    Else
  447.      If FDS.BOF = True Then
  448.        cst = cst & "(BOF) of " & CStr(FNumbRows)
  449.        ClearDataFields
  450.      ElseIf FDS.EOF = True Then
  451.        cst = cst & "(EOF) of " & CStr(FNumbRows)
  452.        ClearDataFields
  453.      Else
  454.        cst = cst + CStr(FCurrRec) & " of " & CStr(FNumbRows)
  455.        'place the data in the form fields
  456.        For i = 0 To FDS.Fields.Count - 1
  457.          If FDS(i).Type = FT_MEMO Then
  458.            If FDS(i).FieldSize() < GETCHUNK_CUTOFF Then
  459.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  460.            Else
  461.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i).GetChunk(0, GETCHUNK_CUTOFF)))
  462.            End If
  463.          ElseIf FDS(i).Type = FT_STRING Then
  464.            cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  465.          Else
  466.            cFieldData(i) = vFieldVal(FDS(i))
  467.          End If
  468.        Next
  469.      End If
  470.    End If
  471.    If FDS.Updatable = False Then cst = cst & "  [Not Updatable]"
  472.    cStatusBar = cst
  473.    'set the flag
  474.    FFldDataChanged = False
  475.    GoTo DCREnd
  476. DCRErr:
  477.   ShowError
  478.   Resume DCREnd
  479. DCREnd:
  480.    ResetMouse Me
  481. End Sub
  482. Sub EditButton_Click ()
  483.    On Error GoTo EditErr
  484.    FDS.Edit
  485.    cStatusBar = "Edit record"
  486.    FEditFlag = True
  487.    cFieldData(0).SetFocus
  488.    FBM = FDS.Bookmark
  489.    ChangeButtons.Visible = True
  490.    ViewButtons.Visible = False
  491.    NextButton.Enabled = False
  492.    FirstButton.Enabled = False
  493.    LastButton.Enabled = False
  494.    PrevButton.Enabled = False
  495.    GoTo EditEnd
  496. EditErr:
  497.   ShowError
  498.   Resume EditEnd
  499. EditEnd:
  500. End Sub
  501. Sub FilterButton_Click ()
  502.   On Error GoTo FilterErr
  503.   Dim bm As String
  504.   Dim ds1 As Dynaset, ds2 As Dynaset
  505.   Dim FilterStr As String
  506.   bm = FDS.Bookmark        'save the bookmark
  507.   Set ds1 = FDS            'save the dynaset
  508.   FilterStr = InputBox("Enter Filter Expression:")
  509.   If Len(FilterStr) = 0 Then Exit Sub
  510.   SetHourglass Me
  511.   MsgBar "Setting New Filter", True
  512.   FDS.Filter = FilterStr
  513.   Set ds2 = FDS.CreateDynaset()            'establish the filter
  514.   Set FDS = ds2            'assign back to original dynaset object
  515.   'everything must be okay so redisplay form on 1st record
  516.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  517.   FCurrRec = 1
  518.   DisplayCurrentRecord     'display field values
  519.   FAtTop = True
  520.   ResetMouse Me
  521.   MsgBar NULL_STR, False
  522.   GoTo FilterEnd
  523. FilterErr:
  524.   ResetMouse Me
  525.   MsgBar NULL_STR, False
  526.   ShowError
  527.   Set FDS = ds1            're-assign back to original
  528.   FDS.Bookmark = bm        'go back to original record
  529.   Resume FilterEnd
  530. FilterEnd:
  531. End Sub
  532. Sub FindButton_Click ()
  533.   Dim i As Integer
  534.   Dim bm As String
  535.   On Error GoTo FindErr
  536.   'load the column names into the find form
  537.   If FFindForm.cFieldList.ListCount = 0 Then
  538.     For i = 0 To FDS.Fields.Count - 1
  539.       FFindForm.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  540.     Next
  541.   End If
  542. FindStart:
  543.   'reset the flags
  544.   gfFindFailed = False
  545.   gfFromTableView = False
  546.   FNotFound = False
  547.   MsgBar "Enter Search Parameters", False
  548.   FFindForm.Show MODAL
  549.   MsgBar "Searching for New Record", True
  550.   If gfFindFailed = True Then   'find cancelled
  551.     GoTo AfterWhile
  552.   End If
  553.   SetHourglass Me
  554.    i = FFindForm.cFieldList.ListIndex
  555.    'search for the record
  556.    bm = FDS.Bookmark
  557.    If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  558.      FDS.FindFirst AddBrackets((FDS(i).Name)) & " " & gstFindOp & " '" & gstFindExpr & "'"
  559.    Else
  560.      FDS.FindFirst AddBrackets((FDS(i).Name)) + gstFindOp + gstFindExpr
  561.    End If
  562.    FNotFound = FDS.NoMatch
  563. AfterWhile:
  564.    ResetMouse Me
  565.    If gfFindFailed = True Then   'go back to top
  566.      FDS.Bookmark = bm
  567.    ElseIf FNotFound Then
  568.      Beep
  569.      MsgBox "Record Not Found", 48
  570.      FDS.Bookmark = bm
  571.      GoTo FindStart
  572.    Else
  573.      bm = FDS.Bookmark
  574.      FDS.MoveFirst
  575.      FCurrRec = 1
  576.      While FDS.Bookmark <> bm
  577.        FCurrRec = FCurrRec + 1
  578.        FDS.MoveNext
  579.      Wend
  580.    End If
  581.    DisplayCurrentRecord
  582.    GoTo FindEnd
  583. FindErr:
  584.    ResetMouse Me
  585.    If Err <> EOF_ERR Then
  586.      ShowError
  587.      Resume FindEnd
  588.    Else
  589.      FNotFound = True
  590.      Resume Next
  591.    End If
  592. FindEnd:
  593.    MsgBar NULL_STR, False
  594. End Sub
  595. Sub FirstButton_Click ()
  596.    Dim ds As String
  597.    On Error GoTo GoFirstError
  598.    FDS.MoveFirst
  599.    FCurrRec = 1
  600.    DisplayCurrentRecord
  601.    FAtTop = True
  602.    GoTo GoFirstEnd
  603. GoFirstError:
  604.    ShowError
  605.    Resume GoFirstEnd
  606. GoFirstEnd:
  607.    ResetMouse Me
  608.    MsgBar NULL_STR, False
  609. End Sub
  610. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  611.   If FEditFlag = True Or FAddNewFlag = True Then Exit Sub
  612.   Select Case KeyCode
  613.     Case 35                'end
  614.       Call LastButton_Click
  615.     Case 36                'home
  616.       Call FirstButton_Click
  617.     Case 38                'up arrow
  618.       If Shift = 2 Then
  619.         Call FirstButton_Click
  620.       Else
  621.         Call PrevButton_Click
  622.       End If
  623.     Case 40                'down arrow
  624.       If Shift = 2 Then
  625.         Call LastButton_Click
  626.       Else
  627.         Call NextButton_Click
  628.       End If
  629.     Case 114                'F3
  630.       Call FindButton_Click
  631.   End Select
  632. End Sub
  633. Sub Form_Load ()
  634.    Dim t As TableDef       'local table structure
  635.    Dim sp As Integer       'starting point of table name
  636.    Dim ep As Integer       'ending point of table name
  637.    Dim ds As String        'temp dynaset name string
  638.    Dim wh As String        'where clause
  639.    Dim ft As Integer
  640.    Dim i As Integer, j As Integer
  641.    Dim fn As String        'field name
  642.    Dim l As Long
  643.    Dim qd As QueryDef      'querydef for parameterized query
  644.    Dim p_query As Integer  'param query flag
  645.    Dim p_val As String     'param value
  646.    Dim Start1, Finish1, Start2, Finish2
  647.    On Error GoTo DynasetErr
  648.    SetHourglass Me
  649.    MsgBar "Opening Dynaset", True
  650.    'disable match case checkbox on find form
  651.    'because it isn't implemented on this form
  652.    FFindForm.cMatchCase.Enabled = False
  653.    'assign the temp string with the select statement
  654.    'if it is not empty, otherwise, use the table list name
  655.    If gfFromSQL = True Then
  656.      If Len(gstDynaString) = 0 Then
  657.        ds = fSQL.cSQLStatement
  658.      Else
  659.        ds = gstDynaString
  660.      End If
  661.    ElseIf Len(gstTableDynaFilter) > 0 Then
  662.      ds = gstTableDynaFilter
  663.    Else
  664.      ds = fTables.cTableList
  665.    End If
  666.    'check for parameters
  667.    If InStr(ds, "PARAM1") > 0 Or InStr(gstDynaString, "PARAM1") > 0 Then
  668.      'figure out if it is a saved querydef
  669.      If Mid(UCase(ds), 1, 7) = "SELECT " Then
  670.        Set qd = gCurrentDB.CreateQueryDef("temp_qd", ds)
  671.        p_query = 1
  672.      Else
  673.        Set qd = gCurrentDB.OpenQueryDef(fTables.cTableList)
  674.        p_query = 2
  675.      End If
  676.      'get the parameter value(s)
  677.      For i = 1 To 4
  678.        p_val = ""
  679.        p_val = InputBox("Enter the value for parameter " & i)
  680.        Select Case i
  681.          Case 1
  682.            qd!PARAM1 = p_val
  683.          Case 2
  684.            qd!PARAM2 = p_val
  685.          Case 3
  686.            qd!PARAM3 = p_val
  687.          Case 4
  688.            qd!PARAM4 = p_val
  689.        End Select
  690.        If InStr(ds, "PARAM" & i + 1) = 0 And InStr(gstDynaString, "PARAM" & i + 1) = 0 Then Exit For
  691.      Next
  692.    End If
  693.    'attemp to open the dynaset
  694.    Start1 = TimeGetTime()
  695.    If gfFromSQL = True Then
  696.      If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  697.        Set FDS = gCurrentDB.CreateDynaset(ds, VBDA_SQLPASSTHROUGH)
  698.      Else
  699.        Set FDS = gCurrentDB.CreateDynaset(ds)
  700.      End If
  701.    Else
  702.      If p_query = 0 Then
  703.        If VDMDI.cPassThru.Visible = True And VDMDI.cPassThru = 1 Then
  704.          ds = "select * from " & StripOwner(ds)
  705.          Set FDS = gCurrentDB.CreateDynaset(ds, VBDA_SQLPASSTHROUGH)
  706.        Else
  707.          Set FDS = gCurrentDB.CreateDynaset(ds)
  708.        End If
  709.      Else
  710.        Set FDS = qd.CreateDynaset()
  711.        qd.Close
  712.        If p_query = 1 Then gCurrentDB.DeleteQueryDef "temp_qd"
  713.      End If
  714.    End If
  715.    Finish1 = TimeGetTime()
  716.    Start2 = TimeGetTime()
  717.    'parse off table name to store in global gstTblName
  718.    wh = NULL_STR
  719.    sp = InStr(1, UCase(ds), "FROM")
  720.    If sp > 0 Then
  721.      'must be a "select from" statement
  722.      sp = sp + 5
  723.      For ep = sp To Len(ds)
  724.        'search for a space or the end of ds
  725.        If Mid$(ds, ep, 1) = " " Or Mid$(ds, ep, 1) = Chr(13) Then
  726.          'get where clause if there is one
  727.          wh = Mid$(ds, sp, Len(ds) - sp + 1)
  728.          Exit For
  729.        End If
  730.      Next
  731.      FTblName = UCase(Mid$(ds, sp, ep - sp))
  732.      If Len(wh) = 0 Then wh = FTblName
  733.    Else
  734.      'must be a table name only
  735.      FTblName = UCase(ds)
  736.      wh = FTblName
  737.    End If
  738.    FDynaString = wh
  739.    'show the first record
  740.    FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  741.    'load the controls on the dynaset form
  742.    cFieldName(0).Visible = True
  743.    cFieldData(0).Visible = True
  744.    ft = FDS(0).Type
  745.    cFieldData(0).Width = GetFieldWidth(ft)
  746.    If ft = FT_STRING Then cFieldData(0).MaxLength = FDS(0).Size
  747.    cFieldData(0).TabIndex = 0
  748.    For i = 1 To FDS.Fields.Count - 1
  749.      cFields.Height = cFields.Height + 300
  750.      Load cFieldName(i)
  751.      cFieldName(i).Top = cFieldName(i - 1).Top + 300
  752.      cFieldName(i).Visible = True
  753.      Load cFieldData(i)
  754.      cFieldData(i).Top = cFieldData(i - 1).Top + 300
  755.      cFieldData(i).Visible = True
  756.      ft = FDS.Fields(i).Type
  757.      cFieldData(i).Width = GetFieldWidth(ft)
  758.      If ft = FT_STRING Then cFieldData(i).MaxLength = FDS(i).Size
  759.      cFieldData(i).TabIndex = i
  760.    Next
  761.    'resize main window
  762.    If i <= 10 Then
  763.      Height = ((i + 1) * 300) + 1400
  764.    Else
  765.      Height = 4368
  766.      Width = Width + 260
  767.      cScrollBar.Visible = True
  768.      cScrollBar.Min = 720
  769.      cScrollBar.Max = 720 - (i * 300) + 3000
  770.    End If
  771.    'display the field names
  772.    For i = 0 To FDS.Fields.Count - 1
  773.      cFieldName(i) = UCase(FDS(i).Name) & ":"
  774.    Next
  775.    FCurrRec = 1
  776.    DisplayCurrentRecord      'display field values
  777.    FAtTop = True
  778.    If Len(gstTableDynaFilter) > 0 Then
  779.      caption = "Filtered Dynaset: " & FTblName
  780.    Else
  781.      caption = "Dynaset: " & FTblName
  782.    End If
  783.    Width = 5805
  784.    Left = 1000
  785.    Top = 1000
  786.    Finish2 = TimeGetTime()
  787.    If VDMDI.PrefShowPerf.Checked Then
  788.      Me.Show
  789.      MsgBox FNumbRows & " rows found in " & (Finish1 - Start1) / 1000 & " seconds!" & Chr(13) & Chr(10) & (Finish2 - Start2) / 1000 & " seconds to Get Record Count!", 48
  790.    End If
  791.    GoTo OkayEnd
  792. DynasetErr:
  793.    If p_query = 1 Then
  794.      gCurrentDB.DeleteQueryDef "temp_qd"
  795.    End If
  796.    ShowError
  797.    ResetMouse Me
  798.    Unload Me
  799.    MsgBar NULL_STR, False
  800.    Exit Sub
  801.    Resume OkayEnd
  802. OkayEnd:
  803.    ResetMouse Me
  804.    MsgBar NULL_STR, False
  805.    Exit Sub
  806. End Sub
  807. Sub Form_Paint ()
  808.   Outlines Me
  809. End Sub
  810. Sub Form_Resize ()
  811.   On Error Resume Next
  812.   Dim h As Integer, i As Integer
  813.   Dim totw As Integer
  814.   If WindowState <> 1 Then   'not minimized
  815.     MsgBar "Resizing Form", True
  816.     'make sure the form is lined up on a field
  817.     h = Height
  818.     If (h - 1420) Mod 300 <> 0 Then
  819.       Height = ((h - 1420) \ 300) * 300 + 1420
  820.     End If
  821.     'resize the status bar
  822.     StatBox.Top = Height - 650
  823.     'resize the scrollbar
  824.     cScrollBar.Height = StatBox.Top - (ViewButtons.Top - FieldHeader.Height) - 960
  825.     cScrollBar.Left = Width - 360
  826.     If FDS.Fields.Count > 10 Then
  827.       cFields.Width = Width - 260
  828.       totw = cScrollBar.Left - 20
  829.     Else
  830.       cFields.Width = Width - 20
  831.       totw = Width - 50
  832.     End If
  833.     FieldHeader.Width = Width - 20
  834.     'widen the fields if possible
  835.     For i = 0 To FDS.Fields.Count - 1
  836.       cFieldName(i).Width = .3 * totw
  837.       cFieldData(i).Left = cFieldName(i).Width + 20
  838.       If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  839.         cFieldData(i).Width = .7 * totw - 250
  840.       End If
  841.     Next
  842.     FieldValueLabel.Left = cFieldData(0).Left
  843.     cStatusBar.Width = Width - 1600
  844.     NextButton.Left = cStatusBar.Width + 745
  845.     LastButton.Left = NextButton.Left + 370
  846.   End If
  847.   MsgBar NULL_STR, False
  848. End Sub
  849. Sub Form_Unload (Cancel As Integer)
  850.   On Error Resume Next
  851.   Unload FFindForm   'get rid of attached find form
  852.   FDS.Close          'close the form dynaset
  853.   MsgBar NULL_STR, False
  854. End Sub
  855. Sub LastButton_Click ()
  856.    On Error GoTo GoLastError
  857.    FDS.MoveLast
  858.    'show the current record
  859.    FCurrRec = FNumbRows
  860.    DisplayCurrentRecord
  861.    GoTo GoLastEnd
  862. GoLastError:
  863.    ShowError
  864.    Resume GoLastEnd
  865. GoLastEnd:
  866. End Sub
  867. Sub NextButton_Click ()
  868.    On Error GoTo GoNextError
  869.    FDS.MoveNext
  870.    'show the current record
  871.    FCurrRec = FCurrRec + 1   'bump the record counter
  872.    DisplayCurrentRecord
  873.    FAtTop = False
  874.    GoTo GoNextEnd
  875. GoNextError:
  876.    ShowError
  877.    Resume GoNextEnd
  878. GoNextEnd:
  879. End Sub
  880. Sub PrevButton_Click ()
  881.    On Error GoTo GoPrevError
  882.    FDS.MovePrevious
  883.    'show the current record
  884.    FCurrRec = FCurrRec - 1   'bump the record counter back
  885.    DisplayCurrentRecord
  886.    FAtTop = False
  887.    GoTo GoPrevEnd
  888. GoPrevError:
  889.    ShowError
  890.    Resume GoPrevEnd
  891. GoPrevEnd:
  892. End Sub
  893. Sub PropButton_Click ()
  894.    Dim f As New fDataBox
  895.    On Error GoTo DynPropErr
  896.    Set gCurrentDS = FDS
  897.    f.Caption = "Dynaset Properties"
  898.    f.Tag = "DS"
  899.    f.cData.AddItem "Name = " & FDS.Name
  900.    f.cData.AddItem "BOF Flag = " & stTrueFalse((FDS.BOF))
  901.    f.cData.AddItem "BookMark = " & FDS.Bookmark
  902.    f.cData.AddItem "BookMarkable Flag = " & stTrueFalse((FDS.Bookmarkable))
  903.    f.cData.AddItem "EOF Flag = " & stTrueFalse((FDS.EOF))
  904.    f.cData.AddItem "Filter = " & FDS.Filter
  905.    f.cData.AddItem "Last Modified = " & FDS.LastModified
  906.    f.cData.AddItem "Lock Edits Flag = " & stTrueFalse((FDS.LockEdits))
  907.    f.cData.AddItem "No Match Flag = " & stTrueFalse((FDS.NoMatch))
  908.    f.cData.AddItem "Sort = " & FDS.Sort
  909.    f.cData.AddItem "Transactions Flag = " & stTrueFalse((FDS.Transactions))
  910.    f.cData.AddItem "RecordCount = " & FDS.RecordCount
  911.    f.cData.AddItem "Updatable Flag = " & stTrueFalse((FDS.Updatable))
  912.    f.Show MODAL
  913.   GoTo DynPropEnd
  914. DynPropErr:
  915.   f.cData.AddItem Error$
  916.   Resume Next
  917. DynPropEnd:
  918. End Sub
  919. Sub SortButton_Click ()
  920.   On Error GoTo SortErr
  921.   Dim bm As String
  922.   Dim ds1 As Dynaset, ds2 As Dynaset
  923.   Dim SortStr As String
  924.   bm = FDS.Bookmark        'save the bookmark
  925.   Set ds1 = FDS            'save the dynaset
  926.   SortStr = InputBox("Enter Sort Column:")
  927.   If Len(SortStr) = 0 Then Exit Sub
  928.   SetHourglass Me
  929.   MsgBar "Setting New Sort Order", True
  930.   FDS.Sort = SortStr
  931.   Set ds2 = FDS.CreateDynaset()            'establish the Sort
  932.   Set FDS = ds2            'assign back to original dynaset object
  933.   'everything must be okay so redisplay form on 1st record
  934.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  935.   FCurrRec = 1
  936.   DisplayCurrentRecord     'display field values
  937.   FAtTop = True
  938.   ResetMouse Me
  939.   MsgBar NULL_STR, False
  940.   GoTo SortEnd
  941. SortErr:
  942.   ResetMouse Me
  943.   MsgBar NULL_STR, False
  944.   ShowError
  945.   Set FDS = ds1            're-assign back to original
  946.   FDS.Bookmark = bm        'go back to original record
  947.   Resume SortEnd
  948. SortEnd:
  949. End Sub
  950. Sub UpdateButton_Click ()
  951.   On Error GoTo UpdateErr
  952.   FDS.Update
  953.   If gfTransPending Then gfDBChanged = True
  954.   If FAddNewFlag = True Then
  955.     FNumbRows = FNumbRows + 1
  956.     FCurrRec = FNumbRows
  957.     FDS.MoveLast             'move to the new record
  958.   End If
  959.   ChangeButtons.Visible = False
  960.   ViewButtons.Visible = True
  961.   NextButton.Enabled = True
  962.   FirstButton.Enabled = True
  963.   LastButton.Enabled = True
  964.   PrevButton.Enabled = True
  965.   FEditFlag = False
  966.   FAddNewFlag = False
  967.   DisplayCurrentRecord
  968.   GoTo UpdateEnd
  969. UpdateErr:
  970.   ShowError
  971.   Resume UpdateEnd
  972. UpdateEnd:
  973. End Sub
  974.